package com.example.meterialproject.activitys.transition.demo3

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.LinearLayout
import androidx.core.app.ActivityOptionsCompat
import com.example.meterialproject.activitys.transition.demo2.TransitionDemoTo2Activity
import com.example.meterialproject.base.BaseActivity
import com.example.meterialproject.databinding.ActivityDemoForm3Binding
import com.example.meterialproject.exts.click
import com.example.meterialproject.exts.dp
import com.example.meterialproject.exts.szj.szj

/**
 *
 * @ClassName: TransitionDemoForm3Activity
 * @Author: android 超级兵
 * @CreateDate: 4/27/22$ 4:55 PM$
 * TODO
 */
class TransitionDemoForm3Activity : BaseActivity<ActivityDemoForm3Binding>() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        (0..20).map {
            val randomColor = applicationContext.szj.randomColor((255 * 0.4).toInt())
            val view = View(this).apply {
                // 随机颜色
                setBackgroundColor(randomColor)
            }

            view.transitionName = "$it"

            view.click {

                val bundle =
                    ActivityOptionsCompat.makeSceneTransitionAnimation(this,
                        view, view.transitionName).toBundle()

                Intent(this, TransitionDemoTo2Activity::class.java).apply {
                    putExtra(TransitionDemoTo2Activity.BACKGROUND_COLOR, randomColor)
                    putExtra(TransitionDemoTo2Activity.TRANSITION_NAME, view.transitionName)
                }.also { intent ->
                    startActivity(intent, bundle)
                }
            }

            binding.linearParent.addView(view, LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                50.dp(applicationContext).toInt()
            ).apply {
                bottomMargin = 5
            })
        }
    }
}